//
// Created by Administrator on 2021/11/10.
// opengl 应用框架，基于GLFW
//

#ifndef LEARNREALTIMERENDERING_APPLICATION_H
#define LEARNREALTIMERENDERING_APPLICATION_H

#include "Common.h"
#include "GLFW/glfw3.h"

#include <string>

class Application
{
public:
    Application(const std::string& title, int width, int height);
    virtual ~Application();

    Application(const Application& rhs) = delete;
    Application& operator = (const Application& rhs) = delete;

    void Run();

    static Application* m_App;

protected:
    virtual void OnCreate() = 0;
    virtual void OnRender() = 0;
    virtual void OnDestroy() = 0;

    virtual void OnUpdate() {}
    virtual void OnResize(int width, int height)
    {
        glViewport(0, 0, width, height);
    }
    // mods ->指的是组合按键，shift/ctrl这种，每个有各自的mods，同时按下，
    // mods会执行位运算，以此判断哪些按下哪些没有
    virtual void OnKey(int keyCode, int action, int mods) {}

private:
    static void OnGlfwFramebufferSizeChanged(GLFWwindow* window, int width, int height)
    {
        m_App->OnResize(width, height);
    }

    static void OnGlfwKeyCallback(GLFWwindow* window, int keyCode, int scanCode, int action, int mods)
    {
        m_App->OnKey(keyCode, action, mods);
    }

    std::string m_Title;
    int m_Width;
    int m_Height;

    GLFWwindow* m_Window;
};

#endif //LEARNREALTIMERENDERING_APPLICATION_H
